package com.blog.web.controller;

import com.blog.common.core.domain.R;
import com.blog.common.core.web.domain.AjaxResult;
import com.blog.common.domain.dto.MessageDto;
import com.blog.common.domain.vo.MessageVo;
import com.blog.web.service.MessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 留言控制器
 * </p>
 *
 * @author Valerie
 * @date 2023/3/1
 **/
@Api(tags = "留言模块")
@RestController
public class MessageController {

    @Resource
    private MessageService messageService;

    /**
     * 查看留言列表
     *
     * @return {@link R<List<MessageVo>>} 留言列表
     */
    @ApiOperation(value = "查看留言列表")
    @GetMapping("/messages")
    public R<List<MessageVo>> listMessages(){
        return R.ok(messageService.listMessages());
    }

    /**
     * 添加留言
     *
     * @param messageDto 留言信息
     * @return {@link R<Void>}
     */
    @ApiOperation(value = "添加留言")
    @PostMapping("/messages")
    public R<Void> saveMessage(@Valid @RequestBody MessageDto messageDto) {
        messageService.saveMessage(messageDto);
        return R.ok();
    }

}
